package com.open.pokergames.biz.views.rooms

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.open.pokergames.R
import com.open.pokergames.base.activity.EventBusTitleBaseActivity
import com.open.pokergames.base.entity.AppPageData
import com.open.pokergames.biz.views.rooms.fragments.DeZhou5Fragment
import com.open.pokergames.biz.views.rooms.fragments.DeZhouFragment
import com.open.pokergames.comm.repository.entity.ResultInfo
import com.open.pokergames.texas.repository.entity.RoomEntity
import kotlinx.android.synthetic.main.group_actvity.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class RoomAddActivity : EventBusTitleBaseActivity() {

    companion object {
        var groupId = ""
    }

    override fun onDestroy() {
        super.onDestroy()
        groupId = ""
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.group_actvity)
        groupId = intent.getStringExtra("groupId").toString()
        setViewTitle("创建比赛")

        initView()
    }


    private fun initView() {
        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        titleList.add("德州扑克")
        titleList.add("五张德州")

        initTab(titleList, getFragments())
    }

    private fun getFragments(): List<Fragment> {
        val fragments: ArrayList<Fragment> = ArrayList()
        fragments.add(DeZhouFragment())
        fragments.add(DeZhou5Fragment())
        return fragments
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);

        scrollTab.setTitles(titles) //, 0, titles.size <= 4
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun eventBusCallback(result: ResultInfo<AppPageData<RoomEntity>>) {
    }
}